package com.sptpc.learspring.model;

import com.sptpc.learspring.commom.OrderState;
import lombok.*;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Entity   //实体
@Table(name = "t_order")  //对应那张表
@Setter
@Getter
@AllArgsConstructor   //使用后添加一个构造函数，该构造函数含有所有已声明字段属性参数
@NoArgsConstructor  //使用后创建一个无参构造函数
@Builder   //链式写法
public class Order extends BaseEntity implements Serializable {

    @ManyToMany
    @JoinTable(name = "t_order_drink", joinColumns = {@JoinColumn(name = "drink_order_id")})  //joinColumn声明外键
    @OrderBy("createTime desc")//根据创建时间排序    asc是指定列按升序排列，desc则是指定列按降序排列
    private List<Drink> items;   //饮品名
    private String customer;    //用户
    @Enumerated   //枚举类型注解
    @Column(nullable = true) //对应数据库列表非空值  通常标注在属性之前
    private OrderState state;     //订单状态

    @Override
    public String toString() {
        return "Order{" +
                "id =" + super.getId() +
                ", customer='" + customer + '\'' +
                ", state=" + state +
                ", items=" + items +
                "} ";
    }
}